home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / pseudo.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  104 lines

  1. ; $Id: pseudo.pro,v 1.6 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1982-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO    PSEUDO,LITLO,LITHI,SATLO,SATHI,HUE,LOOPS,COLR
  7. ;+
  8. ; NAME:
  9. ;    PSEUDO
  10. ;
  11. ; PURPOSE:
  12. ;    Generate a pseudo-color table based on the LHB,
  13. ;    (lightness, hue, and brightness) system and load it.
  14. ;
  15. ; CATEGORY:
  16. ;    Z4 - Image processing, color table manipulation.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    PSEUDO, Litlo, Lithi, Satlo, Sathi, Hue, Loops [, Colr]
  20. ;
  21. ; INPUTS:
  22. ;    Litlo:    Starting lightness, from 0 to 100%.
  23. ;
  24. ;    Lithi:    Ending lightness, from 0 to 100%.
  25. ;
  26. ;    Satlo:    Starting saturation, from 0 to 100%.
  27. ;
  28. ;    Sathi:    Ending saturation, from 0 to 100%.
  29. ;
  30. ;    Hue:    Starting hue, in degrees, from 0 to 360.
  31. ;
  32. ;    Loops:    The number of loops of hue to make in the color helix.
  33. ;        This value can range from 0 to around 3 to 5 and it need
  34. ;        not be an integer.
  35. ;
  36. ; OUTPUTS:
  37. ;    No required outputs.
  38. ;
  39. ; OPTIONAL OUTPUT PARAMETERS:
  40. ;    Colr:    A [256,3] integer array containing the red, green, and 
  41. ;        blue color values that were loaded into the color lookup 
  42. ;        tables.  Red = COLR[*,0], Green = COLR[*,1], Blue = COLR[*,1].
  43. ;
  44. ; COMMON BLOCKS:
  45. ;    None.
  46. ;
  47. ; SIDE EFFECTS:
  48. ;    Color tables are loaded.
  49. ;
  50. ; RESTRICTIONS:
  51. ;    None.
  52. ;
  53. ; PROCEDURE:
  54. ;    This procedure generates a pseudo-color table and loads the red,
  55. ;    green, and blue LUTS with the table.  The pseudo-color mapping 
  56. ;    used is generated by first translating from the LHB (lightness, 
  57. ;    hue, and brightness) coordinate system to the LAB coordinate 
  58. ;    system, finding N colors spread out along a helix that spans
  59. ;    this LAB space (supposedly a near maximal entropy mapping for 
  60. ;    the eye, given a particular N) and remapping back into the RGB
  61. ;    space (red, green, and blue color space).  Thus, given N desired 
  62. ;    colors, the output will be N discrete values loaded into the
  63. ;    red LUTs, N discrete values loaded into the blue LUTs, and N
  64. ;    discrete values loaded into the green LUTs. 
  65. ;   
  66. ; MODIFICATION HISTORY:
  67. ;    Adapted from the IIS primitive DPSEU. DMS, Nov, 1982.
  68. ;    Changed common, DMS, Apr, 1987.
  69. ;       MWR:  9/13/94 - The cur_* variables in common block need to be non-zero
  70. ;                       for use with other routines (e.g. XPALETTE).
  71. ;       MWR: 10/27/94 - Changed common block variable names to comply with
  72. ;                       naming convention used by other IDL routines.
  73. ;-   
  74.         COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  75.     ON_ERROR,2                      ;Return to caller if an error occurs
  76.     GAMINV=1./2.            ;Gamma correction, was 1/2.7
  77.     DTOR = .017452393        ;Degs to radians
  78. ;
  79. ;        conversion matrix from x-y-z to r-g-b color coordinates
  80.     CVT = [[2.58,-1.09,.125],[-1.15,2.04,-.295],[-.422,.058,1.17]]
  81. ;
  82.     ZSTEP = FINDGEN(256)        ;From 0 to 255.
  83.     X = ZSTEP/(255./2.) - 1.    ;From -1 to +1
  84.     S = (SATHI-SATLO) * ( 1. -X*X) + SATLO    ;Saturation
  85.     H = (HUE + ZSTEP*(LOOPS*360./256.))*DTOR ;Hue in radians
  86. ;            Into Lab coords from Lsh.
  87.     A = S*COS(H)
  88.     B = S * SIN(H)
  89.     L = (LITHI-LITLO)/255. * ZSTEP + LITLO    ;Liteness
  90. ;        Cvt from LAB to XYZ coordinates.
  91.     T = (L + 16.)/116.
  92.     X = (A/500. + T) ^ 3        ;Into X-Y-Z space from L-a-b
  93.     Y = T^3
  94.     Z = (T - B/200.) ^ 3
  95. ;        Cvt from XYZ to RGB.
  96.     COLR = FIX(([[X],[Y],[Z]] # CVT > 0. < 1.) ^ GAMINV * 255.)
  97. ;               Save the colors in the common block
  98.     r_orig = colr[*,0] & g_orig = colr[*,1] & b_orig=colr[*,2]
  99.         r_curr = r_orig & g_curr = g_orig & b_curr = b_orig
  100.     tvlct,r_orig,g_orig,b_orig
  101.     RETURN
  102. END
  103.  
  104.